package net.swl.linkedvillage.database;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

//import net.sqlcipher.database.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import android.content.Context;
import android.util.Log;

public class SQLParser {
	
	
	private Context contexto;
	public String filename = "sql_create.sql";
	private SQLiteDatabase db;
	
	public SQLParser(Context contexto, SQLiteDatabase db) {
		this.contexto = contexto;
		this.db = db;
	}

	public boolean parse() {

		BufferedReader br = null;
		
		try {
			
			br = new BufferedReader(new InputStreamReader(contexto.getAssets().open(filename)));

			StringBuilder sb = new StringBuilder();
			String line = br.readLine();

			while (line != null) {
				sb.append(line);
				if (line.contains(";")){
					db.execSQL(sb.toString());
					
					sb = new StringBuilder();
				}
				
				
				line = br.readLine();
			}
			String everything = sb.toString();
			br.close();

		} catch (FileNotFoundException e) {
			Log.e("erros", e.toString());
			e.printStackTrace();
			return false;
		} catch (IOException e) {
			Log.e("erros", e.toString());
			e.printStackTrace();
			return false;
		}
		
		return true;

	}
	
	

}
